<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title site-title">
		<legend>
			<a name="fixbar" style="font-size: 16px; color: #ce2424;">请假审核</a>
		</legend>
	</fieldset>
	<table id="ltable" lay-filter="ltable"></table>
	<div id="ju" style="display: none;">
		<form class="layui-form layui-form-pane">
			<div class="layui-form-item layui-form-text">
				<div class="layui-input-block">
					<textarea id="cause" placeholder="请输入原因"  class="layui-textarea"></textarea>
				</div>
			</div>
		</form>
	</div>
	<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="instant">一键同意</button>
  	</div>
</script>
	<script type="text/html" id="barDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="ckpz">查看凭证</button>
		<button class="layui-btn layui-btn-sm" lay-event="agree">同意</button>
		<button class="layui-btn layui-btn-sm" lay-event="refuse">拒绝</button>
  	</div>
</script>

	<script type="text/javascript">
		layui.use('table', function() {
			var table = layui.table;
			table.render({
				elem : '#ltable',
				url : 'askForleave/page',
				id : 'idTest',
				height : 'full-160',
				toolbar : '#toolbarDemo',
				cols : [ [ {
					field : 'tbClass',
					title : '班级',
				}, {
					field : 'stuName',
					title : '姓名'
				}, {
					field : 'startDate',
					title : '开始时间'
				}, {
					field : 'endDate',
					title : '结束时间'
				}, {
					field : 'type',
					title : '请假类型'
				},  {
					field : 'reasonforleave',
					title : '请假原因'
				}, {
					field : 'leavefile',
					hide:true
				}, {
					fixed : 'right',
					title : '功能',
					align : 'center',
					toolbar : '#barDemo',
				} ] ],
				page : true
			});

			table.on('rowDouble',function(obj){
			});

			//监听表头工具事件

			table.on('toolbar(ltable)', function(obj) {
				var checkStatus = table.checkStatus(obj.config.id);
				if (obj.event === "instant") {
					layer.confirm('确认一键同意？', function(index) {
						$.post('askForleave/instant', function(data) {
							layer.msg(data);
							table.reload('idTest', {
								url : 'askForleave/page'
							});
						});
					});
				}
			});

			table.on('tool(ltable)', function(obj) {
				var data = obj.data;
				if (obj.event === "ckpz") {
					var uuid = data.leavefile;
					if (data.id != null || data.id != "") {
						layer.open({
							type : 2,
							shade : 0.3,
							shadeClose : true,
							anim : 5,
							content : 'askForleave/details?id=' + uuid,
							area : [ '550px', '450px' ],
							btn : [ '下载', '关闭' ],
							yes : function(index, layero) {
								window.location.href='download?uuid='+uuid
							    layer.closeAll('iframe');
							},
							btn2 : function(index, layero) {
								layer.closeAll('iframe');
							}
						});
					} else {
						layer.msg("未选中行喔！");
					}

				}
				if (obj.event === "agree") {
					if (data.id != null || data.id != "") {
						layer.confirm('确认同意？', function(index) {
							$.post('askForleave/agree', {
								id : data.id
							}, function(data) {
								layer.msg(data);
								table.reload('idTest', {
									url : 'askForleave/page'
								});
							});

						});
					} else {
						layer.msg("未选中行喔！");
					}

				}
				if (obj.event === "refuse") {
					if (data.id != null || data.id != "") {
						layer.open({
							type : 1,
							shade : false,
							title:"拒绝原因",
							//shadeClose : true,
							anim : 5,
							content : $('#ju'),
							area : [ '400px', '240px' ],
							btn : [ '提交', '关闭' ],
							yes : function() {
								var reason = $("#cause").val();
								$.post('askForleave/refuse', {
									id : data.id,
									reason : reason
								}, function(data) {
									layer.msg(data);
									table.reload('idTest', {
										url : 'askForleave/page'
									});
								});
								$("#cause").val("");
								layer.closeAll('page');
							},
							btn2 : function() {
								$("#cause").val("");
								layer.closeAll('page');
							}
						});
					} else {
						layer.msg("未选中行喔！");
					}

				}

			});
		});
	</script>
</body>
</html>